package com.yxy.chatserver.common;

import lombok.Data;

import java.io.Serializable;

/**
 * 统一返回结果
 * @param <T>
 */
@Data
public class Result<T> implements Serializable {

//    @Serial
//    private static final long serialVersionUID = 1L; // 避免序列化时出现版本不一致
    private Integer code;
    private String msg;
    private T data;

    public static<T> Result<T> success(String msg){
        Result<T> res = new Result<>();
        res.code = 200;
        res.msg = msg;
        return res;
    }

    public static<T> Result<T> success(String msg, T data){
        Result<T> res = new Result<>();
        res.code = 200;
        res.msg = msg;
        res.data = data;
        return res;
    }

    public static<T> Result<T> success(Integer code, T data){
        Result<T> res = new Result<>();
        res.code = code;
        res.data = data;
        return res;
    }

    public static<T> Result<T> error(Integer code, String msg){
        Result<T> res = new Result<>();
        res.code = code;
        res.msg = msg;
        return res;
    }
}
